
// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import store from './store/store.js'

Vue.config.productionTip = false

App.mpType = 'app'

// 封装的展示消息提示的方法
uni.$toast = function (title = '数据加载失败！', duration = 1500) {
  uni.showToast({
    title,
    duration,
    icon: 'none',
  })
}
// 网络请求https://www.npmjs.com/package/@escook/request-miniprogram
import { $http } from '@escook/request-miniprogram'
uni.$http = $http
$http.baseUrl = "https://api-hmugo-web.itheima.net"
$http.beforeRequest = function(options) {
  uni.showLoading({
    title: "数据加载中..."
  })
  if (store.state.m_user.token) {
    // 为请求头添加身份认证字段
    options.header = {
      // 字段的值可以直接从 vuex 中进行获取
      Authorization: store.state.m_user.token,
    }
  }
}
$http.afterRequest = function(response) {
  if (response?.data?.meta.status !== 200) return uni.$toast(response?.data?.meta.msg || '')
  uni.hideLoading()
}

const app = new Vue({
    ...App,
    store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App.vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

/**
 * https://www.bilibili.com/video/BV1834y1676P/?p=177&spm_id_from=pageDriver&vd_source=59c028b6b980fb5a809c4326d074d67b
   https://applet-base-api-t.itheima.net/docs-uni-shop/index.htm#tabbar-%E7%9B%B8%E5%85%B3%E7%9A%84%E9%A1%B5%E9%9D%A2
 */